package com.cn.lycss.util;

import com.cn.lycss.dao.CompanyDao;

import java.io.*;
import java.util.List;

public  class IOTool {
        public static final String SPLIT="\n";
        public static  File node;
    public static void createFile(String path, String fileName) {
        File directory = new File(path);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        File file = new File(path, fileName);
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        node=file;
    }
    public static String writeData(List<String> data) {
//        if (note == null || !note.exists()) {
//            return "error";
//        }
        try {
            OutputStream outputStream = new FileOutputStream(node);
            for (int i = 0; i < data.size(); i++) {
                outputStream.write(data.get(i).getBytes());
                outputStream.write(SPLIT.getBytes());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return "seccess";
    }
    public static String readData() {
        StringBuilder result=new StringBuilder();
        try {
            Reader reader = new FileReader(node);
            int res=0;
            while ((res=reader.read())!=-1){

                result.append((char) res);

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
//        System.out.println(result);
        return result.toString();
    }







}
